import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaRightMenu, WeaLocaleProvider } from 'ecCom';
import { Button, Popconfirm } from 'antd';
import RemindListItemStore from '../../stores/remindStore/RemindListItemStore';

const getLabel = WeaLocaleProvider.getLabel;
@observer
export default class RemindList extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: '',
      startValue: new Date().setDate(1),
      endValue: new Date(),
      store: new RemindListItemStore(),
    };
  }

  componentWillMount() {
    const { store } = this.state;
    const { doNew } = store;
    doNew(this);
  }
  render() {
    const { onOpenContact, deleteRemindByRole } = this.props;
    const { store } = this.state;
    const { id, role, isUnder, sender, saveRemindConf, sellChanceId, contactid, workPlanId, receivecof, senderName, createdate, createtime, content,
      type, receverSpan, receiver, sellchanceid, customer, customerSpan, sellchanceSpan, contacter, contacterSpan, timedSende, timedSendeState, isSystem, sndeDate, sendeTime } = store;
    // 如果为接收人且未确认,显示点击确认
    let showButton = <div />;
    if (isSystem == '1') {
      showButton = <div className="crm-pc-chance-remind-item-button crm-pc-chance-remind-item-button-gray">{getLabel('84239', '系统提醒')}</div>;
    } else if (timedSende == 'true' && timedSendeState == '0') {
      showButton = <div className="crm-pc-chance-remind-item-button crm-pc-chance-remind-item-button-gray">{getLabel('514769', '定时未发送')}</div>;
    } else if (role == '1' && receivecof == '0') {
      showButton = <div className="crm-pc-chance-remind-item-button crm-pc-chance-remind-item-button-bule" onClick={(e) => { saveRemindConf(); e.stopPropagation(); }}>{getLabel('514770', '点击确认')}</div>;
    } else if (role == '0' && receivecof == '0') { // 当前人员为发送人且接收人未确认，显示未确认
      showButton = <div className="crm-pc-chance-remind-item-button crm-pc-chance-remind-item-button-bule">{getLabel('23062', '未确认')}</div>;
    } else if (receivecof == '1') {
      showButton = <div className="crm-pc-chance-remind-item-button crm-pc-chance-remind-item-button-green">{getLabel('18189', '已确认')}</div>;
    } else {
      showButton = <div />;
    }
    const ua = window.navigator.userAgent;
    let showdeleted = false;
    if (ua.match('E-Mobile')) { // 如果在EMPC
      showdeleted = true;
    } else if (!ua.match('E-Mobile') && window.em) { // 如果在EM网页
      showdeleted = false;
    } else {
      showdeleted = true;
    }
    return (
      <div className="crm-pc-chance-remind-item" id={id}>
        <div style={{ position: 'relative', fontSize: '14px' }}>
          {type == 1 ? getLabel('514774', '联系记录评论提醒') : getLabel('514775', '新的提醒')}
          {type == 1 && <span title={getLabel('514773', '相关联系记录')} >
            {showdeleted && <svg style={{ right: '22px', position: 'absolute', margin: '2px 5px 0 0' }} t="1575940512465" className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2038" width="20" height="20" onClick={() => { onOpenContact && onOpenContact(workPlanId); }}>
              <path d="M852.8 74.4H171.2c-53.6 0-97.6 43.2-97.6 97.6v681.6c0 53.6 43.2 97.6 97.6 97.6h681.6c53.6 0 97.6-43.2 97.6-97.6V171.2c-0.8-53.6-44-96.8-97.6-96.8zM756 366.4H268.8V268.8h487.2v97.6z m0 194.4H268.8V463.2h487.2v97.6zM609.6 755.2H268.8V657.6h340.8v97.6z" fill="#409EFF" p-id="2039" />
            </svg>}
          </span>
          }
          {showdeleted && <Popconfirm ecId={`${this && this.props && this.props.ecId || ''}_Popconfirm@1xy4d0`} title={getLabel('514776', '确定要删除此提醒吗？')} placement="leftTop" onConfirm={() => deleteRemindByRole && deleteRemindByRole({ id, type: role == '3' ? 2 : role })}>
            <span title={getLabel('91', '删除')} style={{ right: '0', position: 'absolute' }} >
              <svg t="1575950642921" className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3555" width="22" height="22">
                <path d="M733.855 791.945c0 26.574-21.63 48.203-48.202 48.203H338.347c-26.573 0-48.202-21.63-48.202-48.203V280.257h443.71v511.688zM386.55 193.74c0-5.562 4.326-9.888 9.888-9.888H628.18c5.562 0 9.888 4.326 9.888 9.888v29.045H386.55V193.74z m491.913 29.045H695.54V193.74c0-37.08-30.28-67.36-67.36-67.36H396.438c-37.08 0-67.36 30.28-67.36 67.36v29.045h-183.54c-16.068 0-29.046 12.978-29.046 29.045s12.978 29.045 29.045 29.045h86.518v511.07c0 58.709 47.584 106.293 106.292 106.293h347.306c58.708 0 106.292-47.584 106.292-106.293V280.257h86.518c16.067 0 29.045-12.977 29.045-29.045s-12.978-28.427-29.045-28.427zM512 753.013c16.068 0 29.045-12.978 29.045-29.046v-308.99c0-16.068-12.977-29.045-29.045-29.045s-29.045 12.977-29.045 29.045v308.99c0 16.068 12.977 29.046 29.045 29.046m-135.338 0c16.068 0 29.045-12.978 29.045-29.046v-308.99c0-16.068-12.977-29.045-29.045-29.045s-29.045 12.977-29.045 29.045v308.99c0.618 16.068 13.596 29.046 29.045 29.046m270.676 0c16.067 0 29.045-12.978 29.045-29.046v-308.99c0-16.068-12.978-29.045-29.045-29.045s-29.045 12.977-29.045 29.045v308.99c0 16.068 12.977 29.046 29.045 29.046" fill="#d81e06" p-id="3556" />
              </svg>
            </span>
          </Popconfirm>}
        </div>
        <div className="crm-pc-chance-remind-item-detail" dangerouslySetInnerHTML={{ __html: content }} />
        {customer > 0 && <div>{getLabel('783', '相关客户')}：<a href={`javaScript:openFullWindowHaveBarForCrm('/main/crm/customerView?customerId=${customer}')`}>{customerSpan}</a></div>}
        {sellChanceId > 0 && <div>{getLabel('84372', '相关商机')}：<a href={`javaScript:openFullWindowHaveBarForCrm('/main/crm/chanceView/${customer}/0/${sellChanceId}')`}>{sellchanceSpan}</a></div>}
        {contacter > 0 && <div>{getLabel('84373', '相关联系人')}：<a href={`javaScript:openFullWindowHaveBarForCrm('/main/crm/contacterView?contacterId=${contacter}')`}>{contacterSpan}</a></div>}
        <div className="crm-pc-chance-remind-item-bottom">
          <div>
            <span>
              {getLabel('882', '创建人')}：{showdeleted ? <a onClick={() => { this.onCardClick(`/spa/hrm/index_mobx.html#/main/hrm/card/cardInfo/${sender}`); }} >{senderName}</a> : <a>{senderName}</a>}
            </span>
            <span>
              {getLabel('15525', '接收人')}：{showdeleted ? <a onClick={() => { this.onCardClick(`/spa/hrm/index_mobx.html#/main/hrm/card/cardInfo/${receiver}`); }} >{receverSpan}</a> : <a>{receverSpan}</a>}
            </span>
            <span>
              {sndeDate}
            </span>
            <span>
              {sendeTime}
            </span>
          </div>
          {showButton}
        </div>
      </div>
    );
  }

    onCardClick = (url) => {
      // console.log("点击卡片");
      const { saveRemindConf, sellChanceId } = this.state.store;
      const ua = window.navigator.userAgent;
      if (ua.match('E-Mobile')) { // 如果在EMPC
        em.openLink({
          url, // 要打开链接的地址
          openType: 3, // 打开方式 1:当前窗口 2:新窗口 3:系统默认浏览器
          autoMatch: true, // 是否通过 url，自动匹配 url 对应的 sysId，为 true 时，下面三个 id 不需要
          sysId: '', // 集成系统ID
          corpId: '', // 企业corpid
          agentId: '', // 应用id
          success(res) { },
        });
      } else if (!ua.match('E-Mobile') && window.em) { // 如果在EM网页
        window.open(url);
      } else {
        window.open(url);
      }
    }
}
